package com.zxkj.commonpatrol.adapt;

import android.content.Intent;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.daimajia.swipe.SwipeLayout;
import com.zxkj.commonpatrol.R;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.response.ProjectDetailResponse;
import com.zxkj.commonpatrol.ui.CheckPointDetailActivity;
import com.zxkj.commonpatrol.ui.ProjectCheckPointListActivity;

import java.util.List;

public class ProjectListAdapt extends BaseQuickAdapter<ProjectDetailResponse.Route, BaseViewHolder> {
    public MyProjectDetailCallBack mDataCallBack;
    public String  proName;
    //数据回调接口
    public interface MyProjectDetailCallBack<T> {
        void onDataSuccessCallBack( T t);
        void onDataFailCallBack(T t,T t1);
    }
    public ProjectListAdapt(int layoutResId, @Nullable List<ProjectDetailResponse.Route> data, String proName) {
        super(layoutResId, data);
        this.proName=proName;
    }

    @Override
    protected void convert(BaseViewHolder helper, ProjectDetailResponse.Route item) {
        helper.setText(R.id.tv_upcoming_name, item.getName());
        helper.setText(R.id.tv_num, item.getPointCompletedCount() + "/"+item.getPointTotal());


        SwipeLayout swipeLayout= helper.itemView.findViewById(R.id.swipe);

        swipeLayout.setClickToClose(true);


        helper.setText(R.id.tv_address, item.getRouteTypeName());//項目編號
        helper.setText(R.id.tv_to_address,item.getPatrolDateRange());//客戶
        String  a="";
        if (item.getStatus()==0){
              a="禁用";
        }else{
              a="啟用";
        }
        //  if (item.getStatus()==0){
        //             a="Disable";
        //        }else{
        //              a="Enable";
        //        }
        helper.setText(R.id.tv_pickup_time, a);//位置

        TextView viewById = helper.itemView.findViewById(R.id.tv_upcoming_name);
        TextView viewById1 = helper.itemView.findViewById(R.id.tv_num);
//          if (item.getPointCompletedCount()!=item.getPointTotal()){
//              viewById.setTextColor(getContext().getColor(R.color.red));
//              viewById1.setTextColor(getContext().getColor(R.color.red));
//          }else{
//              viewById.setTextColor(getContext().getColor(R.color.green));
//              viewById1.setTextColor(getContext().getColor(R.color.green));
//          }

        if (item.PatrolResultStatus==1){
            viewById.setTextColor(getContext().getColor(R.color.green));
            viewById1.setTextColor(getContext().getColor(R.color.green));
        }else{
            viewById.setTextColor(getContext().getColor(R.color.red));
            viewById1.setTextColor(getContext().getColor(R.color.red));
        }
         if (item.IsExistsProperty==0){
             swipeLayout.setSwipeEnabled(false);
         }else{
             swipeLayout.setSwipeEnabled(true);
         }
        helper.itemView.findViewById(R.id.rl_Delete).setOnClickListener(v -> {
            swipeLayout.close();
            mDataCallBack.onDataSuccessCallBack(helper.getLayoutPosition());
        });
        swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
            @Override
            public void onStartOpen(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(false);
            }

            @Override
            public void onOpen(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(false);
            }

            @Override
            public void onStartClose(SwipeLayout layout) {

            }

            @Override
            public void onClose(SwipeLayout layout) {
                helper.itemView.findViewById(R.id.cl).setEnabled(true);
            }

            @Override
            public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {

            }

            @Override
            public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {

            }
        });
        helper.itemView.findViewById(R.id.cl).setOnClickListener(v->{

            Intent intent =new Intent(getContext(), ProjectCheckPointListActivity.class);
            intent.putExtra("ProNo",item.getCode());
            intent.putExtra("Name",item.getName());
            intent.putExtra("proName",proName);

            intent.putExtra("RouteTypeCode",item.getRouteTypeCode());
            getContext().startActivity(intent);

        });


    }
    public void setmDataCallBack(MyProjectDetailCallBack mDataCallBack) {
        this.mDataCallBack = mDataCallBack;
    }
}